package com.icode.jsf.converter;

import com.icode.jsf.model.Currency;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import java.math.BigDecimal;

/**
 * User: alexz
 * Date: 14-11-4
 * Time: 下午2:54
 */
public class CurrencyConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
        BigDecimal money = new BigDecimal(value);
        return new Currency("$", money);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
        return value.toString();
    }
}
